import 'package:demo/provider/view_model/base_view_model.dart';
import 'package:demo/provider/widget/base_provider_widget.dart';
import 'package:demo/utils/freshman_guide.dart';
import 'package:demo/utils/gesture.dart';
import 'package:flutter/material.dart';

class ExampleDialogActivityModel extends BaseViewModel {}

class ExampleDialogActivityPage extends StatefulWidget {
  const ExampleDialogActivityPage({Key? key}) : super(key: key);

  @override
  _ExampleDialogActivityState createState() => _ExampleDialogActivityState();
}

class _ExampleDialogActivityState extends State<ExampleDialogActivityPage> {
  late final ExampleDialogActivityModel _model = ExampleDialogActivityModel();

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return BaseProviderWidget<ExampleDialogActivityModel>(
      viewModel: _model,
      onModelReady: (ExampleDialogActivityModel model) {
        Future.delayed(const Duration(seconds: 2), () {
          model.activityDialog = List.filled(2, true);
        });
      },
      dialogLevelWidget: [
        Material(
          child: GestureDetector(
            onTap: GestureUtils.throttle(() => _model.setActivityDialogState(0, false)),
            child: Image.network(
              "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fww4.sinaimg.cn%2Fmw690%2F007a8xCZgy1gtxt2hl69ej31hi37rb2d.jpg&refer=http%3A%2F%2Fwww.sina.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1636703703&t=50b9dddb12a06a990e6c936daeb19802",
              fit: BoxFit.fill,
            ),
          ),
        ),
        FreshmanGuideUtils.checkNeedShowLeadTipsDialog(context, "test", () {
          _model.setActivityDialogState(1, false);
        }),
      ],
      child: Scaffold(
        appBar: AppBar(
          centerTitle: true,
          title: Text("本页面弹出层"),
        ),
        body: ListView.separated(
          itemCount: 50,
          itemBuilder: (BuildContext context, int index) {
            return Container(
              color: Colors.white,
              padding: const EdgeInsets.all(15),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Row(
                    children: [
                      Container(
                        width: 48,
                        height: 48,
                        margin: const EdgeInsets.only(right: 8),
                        decoration: BoxDecoration(
                          shape: BoxShape.circle,
                          image: DecorationImage(
                            fit: BoxFit.fill,
                            image: NetworkImage("https://t7.baidu.com/it/u=1063451194,1129125124&fm=193&f=GIF"),
                          ),
                        ),
                      ),
                      Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text("标题"),
                          Text("子标题"),
                        ],
                      ),
                    ],
                  ),
                  Container(
                    width: 55,
                    height: 35,
                    color: Colors.red,
                    alignment: Alignment.center,
                    child: Text("按钮"),
                  ),
                ],
              ),
            );
          },
          separatorBuilder: (BuildContext context, int index) {
            return Container(color: Colors.orange, height: 1);
          },
        ),
      ),
    );
  }
}
